﻿var securityMaster = 1;
ALLEvents = function (node) {
    if (String(node.id).indexOf('M') == 0) {
        securityMaster = 2;
        ShowMaster(node);
    }
    if (String(node.id).indexOf('G') == 0) {
        ShowGroup(node);
    }
    if (String(node.id).indexOf('U') == 0) {
        ShowUser(node);
    }
    if (String(node.id).indexOf('T') == 0) {
        ShowDevice(node)
    }
};

//close TabPanel
Ext.ux.TabCloseMenu = function() {
    var tabs, menu, ctxItem;
    this.init = function(tp) {
        tabs = tp;
        tabs.on('contextmenu', onContextMenu);
    }
    function onContextMenu(ts, item, me) {
        if (!menu) { // create context menu on first right click
            menu = new Ext.menu.Menu([{
                id: tabs.id + '-close',
                text: _NewForText_CloseCurrent,
                iconCls: "closetabone",
                handler: function() {
                    tabs.remove(ctxItem);
                }
            }, {
                id: tabs.id + '-close-others',
                text: _NewForText_CloseAllExceptCurrent,
                iconCls: "closetaball",
                handler: function() {
                    tabs.items.each(function(item) {
                        if (item.closable && item != ctxItem) {
                            tabs.remove(item);
                        }
                    });
                }
}]);
            }
            ctxItem = item;
            var items = menu.items;
            items.get(tabs.id + '-close').setDisabled(!item.closable);
            var disableOthers = true;
            tabs.items.each(function() {
                if (this != item && this.closable) {
                    disableOthers = false;
                    return false;
                }
            });
            items.get(tabs.id + '-close-others').setDisabled(disableOthers);
            menu.showAt(me.getXY());
        }
    };

    GridMain = function(node, grid, icon) {
        var id = String(node.id)
        var tab = tabs.getItem(id);
        if (!tab) {
            var tab = tabs.add({
                id: id,
                iconCls: icon,
                xtype: "panel",
                title: node.text,
                closable: true,
                layout: "fit",
                items: [grid]

            });
        }
        tabs.setActiveTab(tab);
    };

